package cn.edu.zzuli.message.news.controller;

import cn.edu.zzuli.common.result.Result;
import cn.edu.zzuli.common.result.ResultInfo;
import cn.edu.zzuli.message.news.mapper.OfflineMessageMapper;
import cn.edu.zzuli.message.news.service.WebSocket;
import cn.edu.zzuli.model.entity.WebMessage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/message")
public class OfflineMessageController {

    @Autowired
    private WebSocket webSocket;

    @Autowired
    private OfflineMessageMapper messageMapper;

    @GetMapping("getMessageList")
    public ResultInfo getMessageList(Integer uid,HttpSession session){

        List<WebMessage> webMessageList = messageMapper.selectList(new QueryWrapper<WebMessage>().
                eq("user_no", uid).orderByDesc("date"));

       return Result.ok(webMessageList);
    }

    @GetMapping("test")
    public String test(){
        return "success";
    }
}
